#include "AssetAdder.h"
#include "AssetPool.h"
#include "..\core\src\AssetManager.h"

namespace Xps
{
	AssetAdder::AssetAdder(QWidget* parent, QString title, QString rsc) : QDialog(parent)
	{
		
		content = setupContent();
		QWidget* buttonpanel = setupButtonPanel();
		head = setupHeader(title, rsc);
		QVBoxLayout* layout = new QVBoxLayout();
		
		setFixedWidth(400);
		QDialog::setWindowIcon(QIcon(rsc));
		QDialog::setWindowTitle("Asset Pool");
		setLayout(layout);
		setModal(true);

		layout->addWidget(head);
		layout->addWidget(content);
		layout->addWidget(buttonpanel);
		layout->setMargin(0);
		layout->setSpacing(0);

		connect(okay, SIGNAL(clicked()), this, SLOT(accept()));
		connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
	}

	AssetAdder::~AssetAdder(void)
	{
	}

	QWidget* AssetAdder::setupButtonPanel()
	{

		QWidget* buttonpanel = new QWidget();
		cancel = new QPushButton("Cancel");
		okay = new QPushButton("Okay");
		
		QHBoxLayout* buttonpanel_layout = new QHBoxLayout();
		buttonpanel->setLayout(buttonpanel_layout);
		buttonpanel_layout->insertStretch(0,100);
		buttonpanel_layout->addWidget(cancel);
		buttonpanel_layout->addWidget(okay);
		
		buttonpanel->setFixedHeight(40);


		setTabOrder(okay,cancel);
		//okay->setDefault(true);

		return buttonpanel;
	}

	QWidget* AssetAdder::setupContent()
	{

		QWidget* content = new QWidget();

		content->setStyleSheet("background: white; color: black;");

		return content;
	}

	QWidget* AssetAdder::setupHeader(QString head_text, QString head_rsc)
	{
		QFont headfont("Arial", 16, QFont::Bold);
		QLabel* head = new QLabel();
		QLabel* img = new QLabel(head);
		QLabel* text = new QLabel(head_text,head);
		
		text->setFont(headfont);
		text->setStyleSheet("background: none");

		img->setFixedWidth(80);
		img->setPixmap(QPixmap(head_rsc));
		img->setStyleSheet("background: none");
		
		head->setFixedHeight(80);
		head->setLayout(new QHBoxLayout());
		head->setBaseSize(500,80);
		head->layout()->addWidget(img);
		head->layout()->addWidget(text);
		head->setStyleSheet("background: url(:/rs/images/bg.png)");

		return head;
	}

	void AssetAdder::accept()
	{
		XpsAssets::AssetManager* am = ((Xps::AssetPool*) parent())->am;
		int id = am->createQuestion();
		XpsAssets::IQuestion* q = am->getQuestion(id);
		q->setText("blaaaaaaaaa");

		QDialog::accept();
	}
}
